package org.mspring.mlog.web.freemarker.directive;

import java.io.IOException;
import java.util.Map;

import org.mspring.mlog.core.ServiceFactory;
import org.mspring.mlog.service.stat.PostStatService;
import org.mspring.platform.web.freemarker.DirectiveUtils;
import org.mspring.platform.web.freemarker.directive.AbstractDirectiveModel;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 显示文章点击率
 * 
 * @author Gao Youbo
 * @since 2013年9月6日
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class PostViewsDirectiveModel extends AbstractDirectiveModel {

    @Override
    public void exec(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
        // TODO Auto-generated method stub
        Long views = Long.valueOf(0);
        Long id = DirectiveUtils.getLong("id", params);
        if (id != null) {
            views = ServiceFactory.getBean(PostStatService.class).getViews(id);
        }
        env.getOut().append(views.toString());
    }

}
